class Memento{
    private int state;//需要备份的个数
    public Memento(int state){
        this.state=state;
    }
    public int getState(){
        return this.state;
    }
}
class GameRole{
    private String name;//角色名
    private int state;//生命力

    public GameRole(String name) {
        this.name = name;
    }
    public void setInitState(int state){
        this.state=state;
    }
    public int getState(){
        return this.state;
    }
    public void getInitState(){
        this.state=100;
    }
    public void Fight(){
        this.state=0;
    }
    public void stateDisplay(){
        System.out.println(name+"的生命力为"+state);
    }
    public Memento CreateMemento(){
        return new Memento(this.state);
    }
    public void setMemento(Memento memento){
        this.state=memento.getState();
    }
}
class Caretaker{//管理者类
 private Memento memento;
 public void setMemento(Memento memento){
     this.memento=memento;
 }
 public Memento getMemento(){
     return this.memento;
 }
}
public class Test {
    public static void main(String[] args) {
        GameRole gr=new GameRole("郭靖");
//        获取初始状态并展示
        gr.getInitState();
        gr.stateDisplay();

        Caretaker c=new Caretaker();
        c.setMemento(gr.CreateMemento());

        gr.Fight();
        gr.stateDisplay();

        gr.setMemento(c.getMemento());
        gr.stateDisplay();
    }
}
